<template>
  <h1>{{ msg }}</h1>
  <!-- <p>
    Recommended IDE setup:
    <a href="https://code.visualstudio.com/" target="_blank">VSCode</a>+
    <a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a>
  </p>
  <p>
    <a href="https://vitejs.dev/guide/features.html" target="_blank">Vite Documentation</a>|
    <a href="https://v3.vuejs.org/" target="_blank">Vue 3 Documentation</a>
  </p>-->
  <button type="button" @click="myclick">count is: {{ count }}</button>

  <button @click="otherClick">emit</button>
  <h1>{{rstData ? rstData.name : ''}}</h1>
  <p>
    Edit
    <code>components/HelloWorld.vue</code>to test hot module replacement.
  </p>
</template>
<script setup>
// import { ref, onMounted, defineEmits } from "vue"
import { ref, onMounted } from "vue"
// 定义props
defineProps({
  msg: String
})
onMounted(() => {
  console.log("从mouted进来了")
})
// 获取上下文
// const ctx  = useContext()
// console.log(ctx)
const count = ref(0)
const myclick = function() {
  count.value++
  return count
}
// 定义事件
const emit = defineEmits(["btnClick"])
const otherClick = () => {
  emit("btnClick")
}
let rstData = ref(null)
// mock 数据
fetch("/api/createUser",{
  method: 'get',
  cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
    credentials: 'include', // include, same-origin, *omit
    headers: {
      'content-type': 'application/json'
    }})
  .then(res => {
    // console.log(res)
    return res.json()
  })
  .then(data => {
    console.log(data)
    rstData = data[0]
  })
</script>
<style scoped>
a {
  color: #42b983;
}
</style>
